package com.example.gprcdemo;

/**
 * @Author : ZYB
 * @Date : on 2023/12/14 .
 * @Description :
 */
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.util.Log;

import java.io.FileOutputStream;
import java.io.IOException;

public class FileSaver {
    private static final String TAG = "FileSaver";

    public interface OnSaveFileCallback {
        void onSaveComplete(String filePath);
        void onSaveError(String errorMessage);
    }

    public static void saveFile(Context context, byte[] data, String filePath, OnSaveFileCallback callback) {
        try {
            FileOutputStream outputStream = new FileOutputStream(filePath);
            outputStream.write(data);
            outputStream.close();
            if (callback!=null) {
                callback.onSaveComplete(filePath);
            }
        } catch (IOException e) {
            Log.e(TAG, "Error saving file", e);
            callback.onSaveError("Error saving file: " + e.getMessage());
        }
    }
}
